<script type="text/javascript">
	$(document).ready(function(){
		$('#petition').dataTable();
	});

	function info(pet_id) {
		$('<div>').dialog2({
			autoOpen: true,
			title: "รายละเอียดเพิ่มเติม",
			content: "dlg_petition_info.php?pet_id=" + pet_id + "&petition_type=<?php echo $petition_type ?>",
			id: "modal-info"
		});
	}

	function status(pet_id) {
		$('<div>').dialog2({
			autoOpen: true,
			title: "รายละเอียดเพิ่มเติม",
			content: "dlg_petition_status.php?pet_id=" + pet_id + "&petition_type=<?php echo $petition_type ?>",
			id: "modal-status"
		});
	}
</script>

<?php
	$sql = "SELECT  tbl_salary.pet_id, expenses1_name, expenses2_name, expenses3_name, panngan2_name, panngan3_name, sum(salary) as salary FROM tbl_salary, expenses_lvl1, expenses_lvl2, expenses_lvl3, panngan2, panngan3 WHERE lvl1_id = '" .$_SESSION["lvl1_id"]. "' and expenses_lvl1.expenses1_id = ex1_id and expenses_lvl2.expenses2_id = ex2_id and expenses_lvl3.expenses3_id = ex3_id and panngan2.panngan2_id = tbl_salary.panngan2_id and panngan3.panngan3_id = tbl_salary.panngan3_id
	GROUP BY tbl_salary.pet_id, expenses1_name, expenses2_name, expenses3_name, panngan2_name, panngan3_name
	";
	$db = new myDBS;
	$db->selectDB("account");
	$result = $db->runSQL($sql);

?>

<table id="petition" class="table table-striped" width="100%" >
	<caption><br></caption>
	<thead>
		<tr>
			<th>#</th>
			<th>เลขที่ฎีกา</th>
			<th>แผนงาน</th>
			<th>งาน</th>
			<th>ประเภท</th>
			<th>รายการ</th>
			<th>จำนวนเงิน</th>
			<th>รายละเอียดเพิ่มเติม</th>
			<th>สถานะฏีกา</th>
		</tr>
	</thead>
	<tbody>
	<?php
		$i=0;
		while ( $rows = $db->fetch_object ( $result )){
			$i++;
			echo "<tr>
					<td>$i</td>
					<td>$rows->pet_id</td>
					<td>$rows->panngan2_name</td>
					<td>$rows->panngan3_name</td>
					<td>$rows->expenses2_name</td>
					<td>$rows->expenses3_name</td>
					<td>". number_format($rows->salary, 2)."</td>
					<td><a href=\"javascript:info('$rows->pet_id')\" ><i class='icon-list'></i>&nbsp;ดู</a></td>
					<td><a href=\"javascript:status('$rows->pet_id')\" ><i class='icon-tags'></i>&nbsp;ดู</a></td>
					</tr>
			";

		}
	?>
	</tbody>
</table>